"""
    @author : 计祝兵
    @date : 2024/5/29 13:52
    @file : log_config.py
    @desc : 日志配置
"""

import logging


def set_log_config(log_level):
    # 设置日志输出格式
    LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"

    DATE_FORMAT = "%Y-%m-%d %H:%M:%S "

    logger = logging.getLogger()
    logger.setLevel(log_level)

    # 文件处理器，把所有的日志都输出到执行文件中
    file_handler = logging.FileHandler("info.log", mode="a", encoding="utf-8")
    logger.addHandler(file_handler)

    # 流处理器
    stream_handler = logging.StreamHandler()
    logger.addHandler(stream_handler)

    # error日志输出到error文件中
    error_handler = logging.FileHandler("error.log", mode="a", encoding="utf-8")
    error_handler.setLevel(logging.ERROR)
    logger.addHandler(error_handler)

    log_format = logging.Formatter(fmt=LOG_FORMAT, datefmt=DATE_FORMAT)
    file_handler.setFormatter(log_format)
    stream_handler.setFormatter(log_format)
    error_handler.setFormatter(log_format)
